package com.sinopec.pi.scalaguide.function

/**
 * 闭包示例
 */
object Closure {
    var factor = 3
    val multiplier = (i:Int) => i * factor

    def main(args: Array[String]): Unit = {
        println( "muliplier(1) value = " +  multiplier(1) )
        // 闭包捕获了外部变量 factor，当 factor 改变时，闭包内的计算结果也相应改变
        factor = 4
        println( "muliplier(1) value = " +  multiplier(1) )
    }
}
